package com.qinggeng.framework.config.mq.impl;
import com.alibaba.fastjson.JSONObject;
import com.qinggeng.common.exception.CustomException;
import com.qinggeng.framework.config.mq.dto.MessageAccountDTO;
import com.qinggeng.framework.config.mq.handle.MessageHandle;
import com.qinggeng.project.system.service.IUserAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Slf4j
@Component
public class   AccountAddMoneyHandleImpl implements MessageHandle {
    @Resource
    IUserAccountService userAccountService;
    @Override
    public void handle(String msg) {
        System.out.println("解析handle "+msg);
        try {
            MessageAccountDTO messageAccountDTO=JSONObject.parseObject(msg,MessageAccountDTO.class);
            Long userId=messageAccountDTO.getUserId();
            String money=messageAccountDTO.getMoney();
            userAccountService.addUserAccountMoney(messageAccountDTO.getMessageId(),userId,money);
        }catch (Exception e){
            throw  new CustomException("錯誤"+e.getMessage());
        }
    }

}
